package my.crawler.util;

import java.io.BufferedReader;
import java.io.CharArrayWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import com.aliasi.util.Files;
import com.aliasi.util.Streams;

public class IOUtil {
	public static String readFromFile(String path) {
		try {
			return Files.readFromFile(new File(path));
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

    public static String getString(InputStream in) throws Exception {
        CharArrayWriter charWriter = new CharArrayWriter();
        InputStreamReader inReader = null;
        BufferedReader bufferedReader = null;
        try {
            inReader = new InputStreamReader(in);
            bufferedReader = new BufferedReader(inReader);
            Streams.copy(bufferedReader,charWriter);
        } finally {
            Streams.closeReader(bufferedReader);
            Streams.closeReader(inReader);
            Streams.closeInputStream(in);
        }
        return charWriter.toString();
    }
}
